package com.cn.intelligence.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.intelligence.pojo.EUDataGridResult;
import com.cn.intelligence.pojo.TaotaoResult;
import com.cn.intelligence.pojo.TbOrder;
import com.cn.intelligence.pojo.TbSendProduct;
import com.cn.intelligence.pojo.TbUser;
import com.cn.intelligence.service.CusUserService;
/**
 * 系统管理员信息
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/cus/")
public class CusUserController {

	@Autowired
	CusUserService cusUserService;
	/**
     * 查询用户列表
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public EUDataGridResult getSystemUserList(Integer page,Integer rows,String selectUser){
    	EUDataGridResult euDataGridResult = new EUDataGridResult();
    	if(selectUser!=null && !"".equals(selectUser)){
    		  euDataGridResult =cusUserService.getCusUser(selectUser,page,rows);	
    	}else{
    		 euDataGridResult =cusUserService.getCusUserList(page,rows);	
    	}
        return euDataGridResult;
    }
    /**
     * 添加和修改用户信息
     * @param TbUser
     * @return
     */
    @RequestMapping(value = "andOrUpdateUser",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult andOrUpdateUser(TbUser TbUser){
    	
    	TaotaoResult taotaoResult= cusUserService.insertTbUser(TbUser);
    	return taotaoResult;
    }
    /**
     * 删除用户
     * @param TbUser
     * @return
     */
    @RequestMapping(value = "delete",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult deleteUser(Long ids[]){
  
    	TaotaoResult taotaoResult= cusUserService.deleteUser(ids);
    	return taotaoResult;
    }
    /**
     * 查询用户
     * @param TbUser
     * @return
     */
    @RequestMapping(value = "selectUser",method = RequestMethod.POST)
    @ResponseBody
    public EUDataGridResult selectUser(String username){
        EUDataGridResult euDataGridResult =cusUserService.getCusUser(username,1,10);
        return euDataGridResult;
    }
    /**
     * 发货
     */
    
    @RequestMapping(value = "sendProduct",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult sendProduct(TbOrder tbOrder){
    	TaotaoResult taotaoResult =cusUserService.sendProduct(tbOrder);
        return taotaoResult;
    }
    
    /**
     * 分配发货员
     * @throws Exception 
     */
    
    @RequestMapping(value = "senderfenpei",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult senderfenpei(String orderIds ,String senders,String sendRemark) throws Exception{
    	TaotaoResult taotaoResult =cusUserService.addProductSender(orderIds,senders,sendRemark);
        return taotaoResult;
    }
    
    /**
     * 分配发货员
     * @throws Exception 
     */
    
	@RequestMapping("/selectSender/{orderId}")
    @ResponseBody
    public TaotaoResult selectSender(@PathVariable String orderId) throws Exception{
    	TaotaoResult taotaoResult =cusUserService.findProductSender(orderId);
        return taotaoResult;
    }
    /**
     * 查询订单商品信息
     * @throws Exception 
     */
    
	@RequestMapping("/selectProdByCart/{cartId}")
    @ResponseBody
    public TaotaoResult selectProdByCart(@PathVariable String cartId) throws Exception{
    	TaotaoResult taotaoResult =cusUserService.findProdByCart(cartId);
        return taotaoResult;
    }
    /**
     * 查询订单商品信息
     * @throws Exception 
     */
    
	@RequestMapping("/selectProdByCarts/{cartId}")
    @ResponseBody
    public TaotaoResult selectProdByCarts(@PathVariable String cartId) throws Exception{
    	TaotaoResult taotaoResult =cusUserService.findProdByCarts(cartId);
        return taotaoResult;
    }
}
